{% extends 'base_menu.html' %}
{% block title %}设备管理{% endblock %}
{% block content %}
<div class="container-fluid">
    <h2>设备管理</h2>
    
    <div class="row">
        <div class="col-md-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">传感器状态</h5>
                </div>
                <div class="card-body">
                    <div class="d-flex justify-content-between mb-3">
                        <span>正常</span>
                        <span class="badge bg-success">{{ status_counts.normal }}</span>
                    </div>
                    <div class="d-flex justify-content-between mb-3">
                        <span>预警</span>
                        <span class="badge bg-warning">{{ status_counts.warning }}</span>
                    </div>
                    <div class="d-flex justify-content-between">
                        <span>离线</span>
                        <span class="badge bg-danger">{{ status_counts.offline }}</span>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">维护任务</h5>
                </div>
                <div class="card-body">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>传感器</th>
                                <th>上次维护</th>
                                <th>下次维护</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for sensor in maintenance_list %}
                            <tr>
                                <td>{{ sensor.name }}</td>
                                <td>{{ sensor.last_maintenance|date:'Y-m-d' }}</td>
                                <td>{{ sensor.next_maintenance|date:'Y-m-d' }}</td>
                                <td>{{ sensor.get_status_display }}</td>
                                <td>
                                    <a href="{% url 'sensor-maintenance' sensor.id %}" class="btn btn-sm btn-primary">维护</a>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    
    <div class="row mt-3">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center">
                        <h5 class="card-title mb-0">传感器列表</h5>
                        <a href="{% url 'sensor-list' %}" class="btn btn-sm btn-primary">查看全部</a>
                    </div>
                </div>
                <div class="card-body">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>名称</th>
                                <th>类型</th>
                                <th>位置</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for sensor in sensor_list %}
                            <tr>
                                <td>{{ sensor.name }}</td>
                                <td>{{ sensor.get_sensor_type_display }}</td>
                                <td>{{ sensor.location }}</td>
                                <td>{{ sensor.get_status_display }}</td>
                                <td>
                                    <a href="{% url 'sensor-detail' sensor.id %}" class="btn btn-sm btn-info">详情</a>
                                    <a href="{% url 'sensor-update' sensor.id %}" class="btn btn-sm btn-warning">编辑</a>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}